package br.com.afi.web.util;

/**
 * Tipos de escopo de HTTP.
 * 
 * @author André de Fontana Ignacio
 * @version 1.0
 */
public enum HttpScope
{
	PAGE_CONTEXT("pageContext"), REQUEST("request"), SESSION("session"), SERVLET_CONTEXT("servletContext");

	String name;

	HttpScope( String name )
	{
		this.name = name;
	}

	/**
	 * Obtém o enum através do nome informado. Valores possíveis: pageContext,request,session ou
	 * servletContext.
	 * 
	 * @param name Nome do Escopo
	 * @return Enum
	 */
	public static HttpScope byName( String name )
	{
		HttpScope scope = null;
		if ( "pageContext".equals( name ) )
		{
			scope = PAGE_CONTEXT;
		}
		else if ( "request".equals( name ) )
		{
			scope = REQUEST;
		}
		else if ( "session".equals( name ) )
		{
			scope = SESSION;
		}
		else if ( "servletContext".equals( name ) )
		{
			scope = SERVLET_CONTEXT;
		}

		return scope;
	}

	public String toString()
	{
		return this.name;
	}
}
